require('../assets/css/version-update-bws.scss');
import ClipboardJS from 'clipboard';
import { getWindowWidthAndHeight } from '@/utils/utils';

Vue.component('version-update-bws', {
  name: 'version-update-bws',
  template: `<div class="m-version-box bgWhite" v-if="show">
    <header>
      <img :src="headerUrl">
      <div class="no f-fs-12">最新版本号：{{ updateVersion }}</div>
    </header>
    <div class="tips"><span class="f-fs-18">亲！</span>现网版本由于手机系统兼容性原因，导致部分手机无法正常使用APP在线升级，故采用特殊升级方式。新版本已经解决兼容性问题。<span class="blue-deep">请您点击下方“复制链接”按钮，并在手机自带浏览器上粘贴打开该链接，按页面提示进行升级操作，后继可以正常使用在线升级。</span></div>
    <div class="clip-box">
      <div class="text"><div id="clipText" class="inner">{{ updateUrl }}</div></div>
      <div id="clipBtn" class="button f-tac" data-clipboard-action="copy" data-clipboard-target="#clipText">复制链接</div>
    </div>
    <div class="tips">通过分享页面下载的已经是解决系统兼容性的最新版本，该版本后继可正常使用在线升级。</div>
    <div class="tips f-fs-12 red">温馨提示：如果{{ appSource.nameZhn }}APP弹窗提醒更新，请不要“立即更新”，按照上述提示进行版本升级。给您造成不便，敬请谅解！</div>
  </div>`,
  data () {
    return {
      show: false,
      headerUrl: '',
      updateUrl: '',
      updateVersion: '',
      headerHeight: '100px',//header外补白高度
    }
  },
  created () {

  },
  mounted () {
    const vm = this;

    let osType = this.getUserAgent(), show = false;

    // if (this.appSource.appType == 2) { // 行牛
    //   this.updateUrl = 'https://xiniu.yuantexn.com/xiniu/update.html';
    //   this.headerUrl = 'https://kmsdk.m10027.com:446/appEntry/lib/img/xiniu_update.jpg';
    //   this.updateVersion = 'v1.2.7';
    //   show = this.appSource.currentVersion != 2019080900;
    // }
    if (this.appSource.appType == 5) { // 嘉信5G
      this.updateUrl = 'https://yj.yuantelhrb.net.cn/yijia/update.html';
      this.headerUrl = 'https://kmsdk.m10027.com:446/appEntry/lib/img/yijia_update.jpg';
      this.updateVersion = 'v1.0.5';
      show = this.appSource.currentVersion == 2019072500;
    } else if (this.appSource.appType == 6) { // 吉网通
      this.updateUrl = 'https://qwt.yuanteqwt.com:3443/qwt/update.html';
      this.headerUrl = 'https://kmsdk.m10027.com:446/appEntry/lib/img/qwt_update.jpg';
      this.updateVersion = 'v1.0.4';
      show = this.appSource.currentVersion == 2019062800;
    }
    // if (this.appSource.appType == 7) { // 大秦5G
    //   this.updateUrl = 'https://julian.yuantect.com/julian/update.html';
    //   this.headerUrl = 'https://kmsdk.m10027.com:446/appEntry/lib/img/julian_update.jpg';
    //   this.updateVersion = 'v1.0.2';
    //   show = this.appSource.currentVersion != 2019080900;
    // }

    if (osType == 1 && show) { // 安卓
      this.show = true;
      var clipboard = new ClipboardJS('#clipBtn');

      clipboard.on('success', function (e) {
        vm.errorBubble('复制成功');
        e.clearSelection();
      });

      clipboard.on('error', function (e) {
        vm.errorBubble('请选择“ 拷贝 ”进行复制!');
      });

      // 设置标题
      const { windowWidth } = getWindowWidthAndHeight();
      this.headerHeight = windowWidth * 0.3 + 'px';
    }
  },
  methods: {
    getUserAgent: function () {
      var e = navigator.userAgent,
        t = (navigator.appVersion, e.indexOf("Android") > -1 || e.indexOf("Linux") > -1),
        n = !!e.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
      return t ? 1 : n ? 2 : void 0//1:andriod,2:ios
    },
  }
})